<template>
  <div>
    <zeda-dialog
      v-model="visible"
      width="1200px"
      title="查看详情"
      :before-close="handleClose"
    >
      <Title name="基本信息" :line="true" slot="green">
        <desc-base-info
          :data="info"
          :colnum-info="baseInfo"
          align="right"
          :no-line-height="true"
          label-width="150px"
          class="base-info"
        >
          <template slot="targetType">
            <dict-tag
              :options="dict.type.target_type"
              :value="info.targetType"
            />
          </template>
          <template slot="energyType">
            <dict-tag
              :options="dict.type.energy_type"
              :value="info.energyType"
            />
          </template>
        </desc-base-info>
      </Title>
      <Title name="能耗24节气跟踪" :line="false" class="mt20">
        <el-table
          :data="info.energyQuotaAllocationDetailVoList"
          border
          height="300"
        >
          <el-table-column
            prop="allocationTime"
            label="能耗分配年月"
            width="120"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="solarTermsName"
            label="节气"
            min-width="80"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="allocationQuotaSolarTerms"
            label="节气分配额度P（B2*O）（kwh/m2）"
            min-width="250"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="solarTermsRatio"
            label="分配比O（%）"
            min-width="100"
            align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.solarTermsRatio | dictFee }}
            </template>
          </el-table-column>
          <el-table-column
            prop="solarTermsStartTime"
            label="起止日期"
            min-width="160"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="solarTermsEndTime"
            label="截止日期"
            min-width="160"
            align="center"
          >
          </el-table-column>
        </el-table>
      </Title>

      <form-button
        slot="footer"
        :show-submit-button="false"
        @cancel="handleClose"
      >
      </form-button>
    </zeda-dialog>
  </div>
</template>
<script>
import { detail } from "@/api/quota/allocation";
import FormButton from "@/components/FormButton";
import { mul, formatDate, replaceDigit } from "@/utils/index";
export default {
  dicts: ["energy_type", "target_type"],
  components: {
    FormButton,
  },
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: "" },
  },
  data() {
    return {
      info: {},
    };
  },
  filters: {
    dictFee(val) {
      const text = val ? mul(val, 100) + "%" : "";
      return text;
    },
    formatTime(val) {
      const text = val ? formatDate(val) : "";
      return text;
    },
  },
  computed: {
    baseInfo({ info }) {
      let arr = [];
      arr = [
        {
          label: "用能单位",
          prop: "sysDeptName",
          colNum: 2,
        },
        {
          label: "能耗分配年度",
          prop: "allocationYear",
          colNum: 2,
          unit: "年",
        },
        { label: "版本号", prop: "rationCriterionVersion", colNum: 3 },
        { label: "能耗种类", prop: "energyType", colNum: 3 },
        { label: "指标类型", prop: "targetType", colNum: 3 },
        {
          label: "年度计划预算引导值",
          prop: "assessGuideVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "年度计划预算基准值",
          prop: "assessBaseVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "年度计划预算约束值",
          prop: "assessConstraintVal",
          colNum: 3,
          unit: "kwh/m2",
        },

        {
          label: "调整能耗额度引导值",
          prop: "adjustGuideVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "调整能耗额度基准值",
          prop: "adjustBaseVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "调整能耗额度约束值",
          prop: "adjustConstraintVal",
          colNum: 3,
          unit: "kwh/m2",
        },

        {
          label: "实际分配能耗额度引导值",
          prop: "allocationGuideVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "实际分配能耗额度基准值",
          prop: "allocationBaseVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "实际分配能耗额度约束值",
          prop: "allocationConstraintVal",
          colNum: 3,
          unit: "kwh/m2",
        },
        {
          label: "反馈内容",
          prop: "content",
          colNum: 1,
        },
      ];
      return arr;
    },
  },
  watch: {
    visible(value) {
      if (value && String(this.id).length > 0) {
        this.getInfo();
      }
    },
  },
  methods: {
    getInfo() {
      const that = this;
      detail(that.id)
        .then((res) => {
          if (res.code === 700) {
            that.$message.warning(res.msg);
            return false;
          }
          this.info = res.data;
        })
        .catch((err) => {
          this.info = {};
          // this.$message.error("系统错误,请联系管理员!300077");
        });
    },
    handleClose(status) {
      this.$emit("update:visible", false);
      this.$emit("close", status === true ? status : false);
    },
  },
};
</script>
